<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
<meta name="google-site-verification" content="kYQuniuaRZuL9fq0DATfL7extAwcqWG6Ki286ZMcpak" />
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
<!-- 网站关键字  -->
  <meta name="keywords" content="web前端,前端博客,vue,js，html,css,html5,css3,node,express,git,react">
<!-- 网站作者  -->
  <meta name="author" content="wxb">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"blogwxb.cn","root":"/","scheme":"Gemini","version":"7.7.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="一、用openssl工具生成RSA的公钥和私钥openssl下载地址下载完openssl工具并安装之后，打开openssl文件夹下的bin文件夹，执行openssl.exe程序：如图：">
<meta property="og:type" content="article">
<meta property="og:title" content="前端如何使用RSA加密和解密">
<meta property="og:url" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/index.html">
<meta property="og:site_name" content="会飞的猪的个人博客">
<meta property="og:description" content="一、用openssl工具生成RSA的公钥和私钥openssl下载地址下载完openssl工具并安装之后，打开openssl文件夹下的bin文件夹，执行openssl.exe程序：如图：">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/1.png">
<meta property="og:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/2.png">
<meta property="og:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/3.png">
<meta property="og:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/4.png">
<meta property="og:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/5.png">
<meta property="og:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/6.png">
<meta property="article:published_time" content="2020-05-17T13:25:27.000Z">
<meta property="article:modified_time" content="2020-05-17T13:41:29.173Z">
<meta property="article:author" content="wxb">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/1.png">

<link rel="canonical" href="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>前端如何使用RSA加密和解密 | 会飞的猪的个人博客</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?3bc21ab780489193ab1c6a33159920cd";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">会飞的猪的个人博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://blogwxb.cn/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="wxb">
      <meta itemprop="description" content="主要是分享自己在web前端的一些入的坑，脱的坑的经历，也会是分享一些node后端的知识。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="会飞的猪的个人博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          前端如何使用RSA加密和解密
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-05-17 21:25:27 / 修改时间：21:41:29" itemprop="dateCreated datePublished" datetime="2020-05-17T21:25:27+08:00">2020-05-17</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">前端</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="一、用openssl工具生成RSA的公钥和私钥"><a href="#一、用openssl工具生成RSA的公钥和私钥" class="headerlink" title="一、用openssl工具生成RSA的公钥和私钥"></a>一、用openssl工具生成RSA的公钥和私钥</h1><p><a href="https://oomake.com/download/openssl" target="_blank" rel="noopener">openssl下载地址</a><br>下载完openssl工具并安装之后，打开openssl文件夹下的bin文件夹，执行<font color="#f40">openssl.exe</font>程序：<br>如图：<br><img src="/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/1.png" alt="1.png"></p>
<a id="more"></a>
<h2 id="（1）生成RSA私钥"><a href="#（1）生成RSA私钥" class="headerlink" title="（1）生成RSA私钥"></a>（1）生成RSA私钥</h2><p>打开openssl.exe 后输入<font color="#f40">genrsa -out rsa_private_key.pem 1024</font>   回车会看到结果<br><img src="/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/2.png" alt="2.png"></p>
<p>这时候bin文件夹中看到一个文件名为<font color="#f40">rsa_private_key.pem</font>的文件，用记事本方式打开它，可以看到—–BEGIN RSA PRIVATE KEY—–开头，—–END RSA PRIVATE KEY—–结尾的没有换行的字符串，这个就是原始的私钥。每次使用<font color="#f40">genrsa -out rsa_private_key.pem 1024</font>命令，私钥都会变的。<br><img src="/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/3.png" alt="3.png"></p>
<h2 id="（2）生成RSA公钥"><a href="#（2）生成RSA公钥" class="headerlink" title="（2）生成RSA公钥"></a>（2）生成RSA公钥</h2><p>输入命令：<font color="#f40">rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem</font>，并回车，得到生成成功的结果<br><img src="/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/4.png" alt="4.png"></p>
<p>这时候可以在bin文件夹中看到一个文件名为rsa_public_key.pem的文件，用记事本方式打开它，可以看到—–BEGIN PUBLIC KEY—–开头，—–END PUBLIC KEY—–结尾的没有换行的字符串，这个就是公钥。<br><img src="/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/5.png" alt="5.png"></p>
<h2 id="注意："><a href="#注意：" class="headerlink" title="注意："></a>注意：</h2><p><font color="#f40">必须先生成私钥再生成公钥才行。</font></p>
<h1 id="二、用jsencrypt来进行RSA的加密和解密"><a href="#二、用jsencrypt来进行RSA的加密和解密" class="headerlink" title="二、用jsencrypt来进行RSA的加密和解密"></a>二、用jsencrypt来进行RSA的加密和解密</h1><p>这次我是用的React使用的jsencrypt进行的操作。<br><font color="#f40">使用场景</font></p>
<ul>
<li>需要在本地存储一些标志位，安全问题</li>
<li>用户登录密码的加密<h2 id="（1）安装jsencrypt"><a href="#（1）安装jsencrypt" class="headerlink" title="（1）安装jsencrypt"></a>（1）安装jsencrypt</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install jsencrypt --save</span><br></pre></td></tr></table></figure>
<h2 id="（2）生成一对RSA公钥和私钥"><a href="#（2）生成一对RSA公钥和私钥" class="headerlink" title="（2）生成一对RSA公钥和私钥"></a>（2）生成一对RSA公钥和私钥</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> JSEncrypt <span class="keyword">from</span> <span class="string">'jsencrypt'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 私钥内容</span></span><br><span class="line"><span class="keyword">const</span> PRIV_KEY = <span class="string">`MIICXQIBAAKBgQDsNBA0WAtqWTNan3YrP20wbeIivc/dsXF0GBGLj3LmYrlPfOCa</span></span><br><span class="line"><span class="string">7sr0yzzzSmeb9iloig8C8Ao/swjw6iUdlcPV/pfY/FiFTTMiUNFLF503dvKkPRIf</span></span><br><span class="line"><span class="string">CLgnGb/5ZGunm7u/2W4ForUW1LsphlwUGbRmIOIuMUwXo6c8FR/4GhmqPwIDAQAB</span></span><br><span class="line"><span class="string">AoGBAOBwhClIs+gkxEBLH1zu0tDeyK6cT+Tm09gtepZzAwnZKx5VmZJ+bsl2SP8g</span></span><br><span class="line"><span class="string">ZxzyJdyYurTe484tT8SjqArZoQ9lP6Qs6ngH80WPg9O0dHFF8QD1bHFG2IfSlS40</span></span><br><span class="line"><span class="string">p5Tqlc2WT6RJgIK4NekowC7tPu7PONbf67CUCv2Fi0s3zpopAkEA/+lyaJNyVpA4</span></span><br><span class="line"><span class="string">Bd7mb5tvk8VmcPhHdpNkVuP29Glc74P5+VdsvNvDgo/StYooi8TscDNcIjBGLtom</span></span><br><span class="line"><span class="string">gljLARBqAwJBAOxI4SeYo6Vak8Eib83QiHEcDdM3HxEmzzRZkQJohipZwNGEqCDV</span></span><br><span class="line"><span class="string">WWsrXL2upUOT16xzOElZmnpOsxkRA3llqBUCQQD7AeX2ztCyOSjKEVSiman6Hf+Z</span></span><br><span class="line"><span class="string">xNyLYIxlcZnzJzlBsIhKWcbNAx0j/Z+l8opMdW2Xq7ity/26zLxC04biV1AzAkAJ</span></span><br><span class="line"><span class="string">BUdDQbqNp4WYi/4Et39eAhotBB+1gevLLdgxZVgp6b9IwG3CwyJkywUBYNeCWvSS</span></span><br><span class="line"><span class="string">6tstQbR6EuMXg+TED7N5AkA2xfsjd4z6jG1C6n8GpTo9S+Sz8obk2QUH0EqsN1E6</span></span><br><span class="line"><span class="string">Fg3nV/1B8xdPlhWhy77uC5UEDuJ57+5hj27jKf01CmU/`</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 公钥内容</span></span><br><span class="line"><span class="keyword">const</span> PUB_KEY = <span class="string">`MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDsNBA0WAtqWTNan3YrP20wbeIi</span></span><br><span class="line"><span class="string">vc/dsXF0GBGLj3LmYrlPfOCa7sr0yzzzSmeb9iloig8C8Ao/swjw6iUdlcPV/pfY</span></span><br><span class="line"><span class="string">/FiFTTMiUNFLF503dvKkPRIfCLgnGb/5ZGunm7u/2W4ForUW1LsphlwUGbRmIOIu</span></span><br><span class="line"><span class="string">MUwXo6c8FR/4GhmqPwIDAQAB`</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 公钥加密</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">encrypt</span>(<span class="params">text</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">const</span> encrypt = <span class="keyword">new</span> JSEncrypt();</span><br><span class="line">    encrypt.setPublicKey(PUB_KEY);</span><br><span class="line">    <span class="keyword">const</span> encrypted = encrypt.encrypt(text);</span><br><span class="line">    <span class="keyword">return</span> encrypted;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 私钥解密</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">decrypt</span>(<span class="params">text</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">const</span> decrypt = <span class="keyword">new</span> JSEncrypt();</span><br><span class="line">    decrypt.setPrivateKey(PRIV_KEY);</span><br><span class="line">    <span class="keyword">const</span> decrypted = decrypt.decrypt(text);</span><br><span class="line">    <span class="keyword">return</span> decrypted;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(encrypt(<span class="string">"我是一段数据"</span>))  <span class="comment">// 加密</span></span><br><span class="line"><span class="built_in">console</span>.log(decrypt(encrypt(<span class="string">"我是一段数据"</span>)))  <span class="comment">// 解密</span></span><br></pre></td></tr></table></figure>
运行结果：<br><img src="/2020/05/17/%E5%89%8D%E7%AB%AF%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8RSA%E5%8A%A0%E5%AF%86%E5%92%8C%E8%A7%A3%E5%AF%86/6.png" alt="6.png"></li>
</ul>

    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="wxb 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="wxb 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/JavaScript/" rel="tag"># JavaScript</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/05/12/js%E4%B8%AD%E7%94%A8x%EF%BC%8Cy%E5%9D%90%E6%A0%87%E6%9D%A5%E5%AE%9E%E7%8E%B0%E6%A8%A1%E6%8B%9F%E7%82%B9%E5%87%BB%E5%8A%9F%E8%83%BD/" rel="prev" title="js中用x，y坐标来实现模拟点击功能">
      <i class="fa fa-chevron-left"></i> js中用x，y坐标来实现模拟点击功能
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/05/22/React%E4%B8%AD%E7%9A%84proxy/" rel="next" title="React中的proxy">
      React中的proxy <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#一、用openssl工具生成RSA的公钥和私钥"><span class="nav-number">1.</span> <span class="nav-text">一、用openssl工具生成RSA的公钥和私钥</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#（1）生成RSA私钥"><span class="nav-number">1.1.</span> <span class="nav-text">（1）生成RSA私钥</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#（2）生成RSA公钥"><span class="nav-number">1.2.</span> <span class="nav-text">（2）生成RSA公钥</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注意："><span class="nav-number">1.3.</span> <span class="nav-text">注意：</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、用jsencrypt来进行RSA的加密和解密"><span class="nav-number">2.</span> <span class="nav-text">二、用jsencrypt来进行RSA的加密和解密</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#（1）安装jsencrypt"><span class="nav-number">2.1.</span> <span class="nav-text">（1）安装jsencrypt</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#（2）生成一对RSA公钥和私钥"><span class="nav-number">2.2.</span> <span class="nav-text">（2）生成一对RSA公钥和私钥</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="wxb"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">wxb</p>
  <div class="site-description" itemprop="description">主要是分享自己在web前端的一些入的坑，脱的坑的经历，也会是分享一些node后端的知识。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">27</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/dearDreamWeb" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;dearDreamWeb" rel="noopener" target="_blank"><i class="github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/flyingwxb" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;flyingwxb" rel="noopener" target="_blank"><i class="gitee fa-fw"></i>Gitee</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">wxb</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div><script color="0,0,0" opacity="0.5" zIndex="-1" count="99" src="https://cdn.jsdelivr.net/npm/canvas-nest.js@1/dist/canvas-nest.js"></script>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>















  

  

</body>
</html>
